# encoding: utf-8

class AdminMailer < ActionMailer::Base
  default from: "no-reply@china-east.net"
  def release_app(app)
    @app = app
    recipients = app.staff_emails.split(';').flatten 
    if Rails.env == "production"
      recipients << "service@china-east.net"
      recipients << "wangjianfeng@cloudchain.cn"
      recipients << "liwenjiang@cloudchain.cn"
      recipients << "xupeng@cloudchain.cn"
    else
      recipients << "sharp@china-east.net"
    end
    mail(to: recipients, subject: "#{app.display_name} #{app.version} 版本更新了", content_type: "text/html")
  end

  def release_notify(title, body, emails)
    emails = emails || ";"
    @title = title
    @body  = body
    recipients = emails.split(';').flatten 
    if Rails.env == "production"
      recipients << "service@china-east.net"
    else
      recipients << "sharp@china-east.net"
    end
    puts recipients.inspect
    mail(to: recipients, subject: @title, content_type: "text/html")
  end

  def warnning_notify(title,body,emails)
    emails = emails || ";"
    @title = title
    @body  = body
    recipients = emails.split(';').flatten 
    if Rails.env == "production"
      recipients << "service@cloudchain.cn"
    else
      recipients << "zhangyaning@cloudchain.cn"
    end
    puts recipients.inspect
    mail(to: recipients, subject: @title, content_type: "text/html")
  end

end
